
#include "vector.h"

static size_t const PUP_VECTOR_FIRST_CAPACITY = 8;

int pup_vector_expand_(pup_vector_t* __restrict__ vector, size_t min_capacity)
{
  size_t new_capacity = pup_vector_capacity(vector) * 2;
  if (min_capacity == 0)
    min_capacity = PUP_VECTOR_FIRST_CAPACITY;
  if (new_capacity < min_capacity)
    new_capacity = min_capacity;
  size_t const size = pup_vector_size(vector);
  if (vector->begin)
    vector->begin = realloc(vector->begin, new_capacity * sizeof(pup_item_t));
  else
    vector->begin = malloc(new_capacity * sizeof(pup_item_t));
  if (!vector->begin)
    return -1;
  vector->end = vector->begin + size;
  vector->alloc_end = vector->begin + new_capacity;
  return 0;
}

